﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StateGrid.OperationLog
{
    class Program
    {
        static OperationLog_DAO dao = new OperationLog_DAO();

        static void Main(string[] args)
        {
            testInsert();
            testQuery();
            
            //以下操作会清空日志数据库，请确认在测试时使用，防止数据丢失
            //testDelete();
        }

        static void testInsert()
        {
            Console.WriteLine("插入测试日志");
            OperationLogItem newLog = new OperationLogItem();
            newLog.opBookIn = "中文期刊00001";
            newLog.opDate = DateTime.Now;
            newLog.opMode = "SINGLE";
            newLog.opObjectID = "testID";
            newLog.opPageCount = 15;
            newLog.opPerson = "测试日志用户";
            newLog.opTable = "ZWQK_PM";
            newLog.opType = "ADD";
            dao.insertLogItem(newLog);
            newLog.opDate = DateTime.Now;
            //连续插入两次
            dao.insertLogItem(newLog);
        }

        static void testQuery()
        {
            Console.WriteLine("测试查询日志");
            LogQueryCondition cond = new LogQueryCondition();
            cond.userName = "测试日志用户";
           
            IList<OperationLogItem> items = dao.queryLogItem(cond);
            foreach (OperationLogItem i in items)
            {
                Console.WriteLine(i.opPerson + " " + i.opDate + " " + i.opObjectID);
            }

            //输出1
            Console.WriteLine("记录数：" + dao.CountRecord(cond));
            
            //输出1
            Console.WriteLine("本数：" + dao.CountBook(cond));
            
            //输出2（因为插入了2次）
            Console.WriteLine("操作数：" + dao.CountOperation(cond));

            //全文页数
            Console.WriteLine("全文页数：" + dao.CountPageCount(cond));
        }

        static void testDelete()
        {
            Console.WriteLine("清空所有之前的日志");
            dao.deleteLogItemBefore(DateTime.Now);
        }
    }
}
